import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import jwtDecode from "jwt-decode"
import routes from "./router";
import store from './store/reducers';
import Navigation from './components/Navigation';
import FlashMessagesList from './components/flash/flashMessagesList';
import { setCurrentUser } from "./store/actions/login";

sessionStorage.token && store.dispatch(setCurrentUser(jwtDecode(sessionStorage.token)));

ReactDOM.render(
  <React.StrictMode>
    <Provider store={store}>
      <BrowserRouter routes={routes}>
        <Navigation />
        <FlashMessagesList />
        {routes}
      </BrowserRouter>
    </Provider>
  </React.StrictMode>,
  document.getElementById('root')
);